<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>电子文档系统</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
	<script type="text/javascript" src="view/jquery/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="view/bootstrap/js/bootstrap.js"></script>
	<link rel="stylesheet" href="view/bootstrap/css/bootstrap.css">
	<link rel="stylesheet" href="view/css/docMan.css">
	<link rel="stylesheet" href="view/toastr/toastr.css">
	<script type="text/javascript" src="view/js/docMan.js"></script>
	<script type="text/javascript" src="view/toastr/toastr.min.js"></script>
	<script type="text/javascript" src="view/js/ajaxfileupload.js"></script>
  </head>
  <body style="background: #EDEFF0;">
  	<div id="main-container" class="container" style="height: 100%;width:90%;background: #ffffff">
  		<div class="row" style="height: 100%">
  			<div id="left-p" class="col-sm-2" style="height: 100%;border-right: 1px solid #d2d2d2;"></div>
  			<div  class="col-sm-10" style="height: 100%;">
  				<div class="row mt_10" style="height:44px;width: 100%">
  					<form action="search.action" method="post">
  						<input type="text" class="form-control" name="param" value='<s:property value="param" />' style="width: 20%;display: inline;">
  						<button class="btn btn-primary btn-search" type="submit">搜索</button>
  						<button id="btn-back" class="btn btn-default  ml_10" >返回上级</button>
  					</form>
  				</div>
  				<!-- <div class="row" style="height: 45px;">
  					<button id="btn-back" class="btn btn-default mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;" onclick="back();">返回上级</button>
  					<button id="btn-uploadFile2disk" class="btn btn-primary mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;">上传</button>
  					<button id="btn-createDirectory-modal" class="btn btn-default mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;">新建文件夹</button>
  					<button id="btn-refresh" class="btn btn-default mt_10 ml_10"  style="height: 25px;padding: 2px 12px 2px 12px;">刷新</button>
  					<button id="del_confirm_btn" class="btn btn-default mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;" >删除</button>
  				</div> -->
  				<%-- <div class="row " style="height: 37px;background: #F9F9F9;border-top: 1px solid #3792e5;" >
  					<div class="ver-middle text-c" style="height:100%;width: 8%;float: left;padding: 7px;">
  						<input type="checkbox" id="del_all_cbx">
  					</div>
  					<div class="ver-middle" style="height: 100%;width: 50%;float: left;padding: 7px;">
  						<span class="bold">名称</span>
  					</div>
  					<div class="ver-middle " style="height: 100%;width: 17%;float:left;padding: 7px;">
  						<span class="bold">创建人</span>
  					</div>
  					<div class="ver-middle" style="height: 100%;width: 25%;float: left;padding: 7px;">
  						<span class="bold">上传时间</span>
  					</div>
  				</div> --%>
  				<div class="row file_list">
	  				<s:iterator value="indexFiles" id="file" status="stu">
						<div class="indexFile border_bottom" style="min-height: 80px;height: 100px;">
							<div class="text-c"
								style="height:100%;width: 8%;float: left;padding:15px 8px;">
								<div class="<s:property value="#file.imageCssClass" />   ico_cnt ml_10"
									style="float: left;"></div>
							</div>
							<div style="height: 100%;width: 50%;float: left;padding: 8px;">
								<div class="row ver-middle" style="float: left">
									<div class="ellipsis">
										<a title="<s:property
												value="#file.fileName" escape="false" />" href="dowloadFile.action?id=<s:property value="#file.fileId" />"
											target="_blank" style="margin-right: 5px;"><span>
											<s:property
												value="#file.fileName" escape="false" />
											</span></a>
									</div>
									<div>
										<span class="muted">
										<s:property value="#file.content" escape="false" />
										</span>
									</div>
									<div class="">
										<span class="muted">[所在位置] 
										<s:if test="#file.humanName=='oa'">来源OA系统</s:if>
										<s:else><s:property
												value="#file.filePath" /></s:else>
										</span>
									</div>
								</div>
							</div>
							<div class="ver-middle"
								style="height: 100%;width: 25%;float: left;padding: 12px 8px;">
								<span class="muted">上传人：<s:property
										value="#file.humanName" />
								</span> <br>
								<span class="muted"><s:property 
										value="#file.createTime" /> </span>
							</div>
						</div>
					</s:iterator>
  				</div>
  			</div>
  		</div>
  	</div>
	<div class="modal fade" id="directoryCreateModal" tabindex="-1" role="dialog" backdrop =“static”
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="false">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">新建文件夹</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<label for="directoryName" class="control-label">文件夹名字:</label>
							<input type="text" class="form-control" id="directoryName" placeholder="文件夹名称长度不能大于30"  >
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" id="btn-directory-creat" class="btn btn-primary">创建</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="directoryAttrModal" tabindex="-1" role="dialog"  aria-hidden="false"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">文件夹信息</h4>
				</div>
				<div class="modal-body">
					<div class="row" >
						<div class="col-xs-3">
							<div class="diskpic-file fr"></div>
						</div>
						<div class="col-xs-9 ">
							<input id="directoryNameAttr" class="form-control" value='' >
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">占用空间：</span>
						</div>
						<div class="col-xs-9">
							<span id="directorySize"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">包含：</span>
						</div>
						<div class="col-xs-9">
							<span id="directoryContain"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">创建信息：</span>
						</div>
						<div class="col-xs-9">
							<span id="directoryCreate"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">所在目录：</span>
						</div>
						<div class="col-xs-9">
							<span id="directoryLocation"></span>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" id="btn-directory-save" value="" class="btn btn-primary">保存</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="uploadFileModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">上传文件</h4>
				</div>
				<div class="modal-body">
					<input type="file" name="oafile" id="upFile" onchange="uploadfile();" style="height: 0px;width: 0px;">
					<div class="row ">
						<div class="col-xs-2" >
							<div style="float: right">
								<span style="color:red;" >* </span>文件：
							</div>
						</div>
						<div  class="col-xs-9">
							<div id="fileUploadList" class="">
								<%-- <div class="row file">
									<div class="col-xs-6">
										<span class=""> 2012新生名单分班人数8月2 </span>
									</div>
									<div class="col-xs-4">
										<span class="muted fileSize"> (1.78M) </span>
										<button  class="btn btn-link padding_clear ">删除</button>
									</div>
								</div> --%>
							</div>
							<div class="row">
								<i class="commpic-attach"></i>
								<button id="" onclick="clickinput();" class="btn btn-link">上传文件</button>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" id="btn-upload-file" class="btn btn-primary">上传</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
	<div id="delModal" class="modal fade">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">关闭</span>
					</button>
					<h4 class="modal-title center bold">文件删除</h4>
				</div>
				<div class="modal-body">
					<div class="row ml_20">
						<span >确认删除这些文件，删除操作无法恢复</span>
					</div>
				</div>

				<div class="modal-footer">
					<div class="row">
						<div class="col-md-3"></div>
						<div class="col-md-4">
							<button type="button" id="btn_del" class="btn btn-danger "
								>删除</button>
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
						<div class="col-md-4"></div>
					</div>
				</div>
			</div>
		</div>

	</div>
	<div id="delDirModal" class="modal fade">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">关闭</span>
					</button>
					<h4 class="modal-title center bold">文件夹删除</h4>
				</div>
				<div class="modal-body">
					<div class="row ml_20">
						<span >确认删除文件夹和文件夹下的所有文件，删除操作无法恢复</span>
					</div>
				</div>

				<div class="modal-footer">
					<div class="row">
						<div class="col-md-3"></div>
						<div class="col-md-4">
							<button type="button" value="" id="btn_deleteDir" class="btn btn-danger "
								>删除</button>
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
						<div class="col-md-4"></div>
					</div>
				</div>
			</div>
		</div>

	</div>
</body>
  <script type="text/javascript">
  $(function(){
	  $("#btn-createDirectory-modal").on("click",function(){
			$("#directoryCreateModal").modal('show');
	  });
	  $("#btn-directory-creat").on("click",function(){
		  var directoryName=$("#directoryName").val().trim();
		  var diskId=string.getUrlParam("diskId");
		  $.ajax({
			 type:"post",
			 url:"/DocMan/webService/show/DocDirectory/saveOrUpdate",
			 data:{name:directoryName,reName:directoryName,id:0,diskId:diskId},
			 success:function(data){
				 console.info(data);
				 var directory="<div class=\"directory border_bottom\" style=\"height: 40px;\">"+
									"<div class=\"text-c\" style=\"height:100%;width: 8%;float: left;padding: 8px;\">"+
									"</div>"+
									"<div style=\"height: 100%;width: 50%;float: left;padding: 8px;\">"+
									"<div style=\"width: 10%;height: 100%;float: left;\">"+
		  								"<div class=\"diskpic-file\"style=\"float: left;\"></div>"+
		  							"</div>"+
									"<div class=\"row ver-middle\" style=\"float: left\">"+
										"<a href=\"directoryView.action?directoryId="+data["directory"].id+"\" style=\"margin-right: 5px;\">"+data["directory"].reName+"</a><span class=\"muted\">(文件夹："+data["directory"].fileCount+"，文件："+data["directory"].directoryCount+")</span>"+
									"</div>"+
								"</div>"+
								"<div class=\"\" style=\"height: 100%;width: 17%;float:left;padding: 7px;\">"+
									"<span class=\"muted\" >"+data["directory"].humanName+"</span>"+
								"</div>"+
								"<div class=\"ver-middle\" style=\"height: 100%;width: 25%;float: left;padding: 7px;\">"+
									"<a href=\"javascript:void(0)\" class=\"btn-directory-attr\" id='"+data["directory"].id+"' style=\"font-size: 12px;color: #06c;\"> 属性 </a>"+
									"<span class=\"muted \" >&nbsp;|&nbsp;</span>"+
									"<a class=\"btn-delDir-modal\" style=\"font-size: 12px;color: #06c;\"> 删除 </a>"+
								"</div>"+
							"</div>";
				 $(".directory_list").append(directory);
				 $("#directoryCreateModal").modal('hide');
			 },
			 error:function(data){
				 toast.error("创建网盘错误", "温馨提示");
			 }
		  });
	  });
	  $("#btn-uploadFile2disk").on("click",function(){
		 $("#uploadFileModal").modal("show");
	  });
	  $("#btn-upload-file").on("click",function(){
		  var filePathsBtn= $("#fileUploadList").find(".filePath");
		  var fileSizeSpans=$("#fileUploadList").find(".fileSize");
		  var diskId=string.getUrlParam("diskId");
		  var filePaths=new Array();
		  var fileSizes=new Array();
		  $(filePathsBtn).each(function(i,e){
			  filePaths[i]=e.value;
		  });
		  $(fileSizeSpans).each(function(i,e){
			 fileSizes[i]=e.id;
		  });
		  
		  $.ajax({
			 type:"post",
			 url:"/DocMan/webService/show/DocFile/createFiles",
			 traditional:true,
			 data:{filePaths:filePaths,fileSizes:fileSizes,id:diskId,type:2},
			 success:function(data){
				 console.info(data);
				 $(data["files"]).each(function(i,e){
					 var fileStr="<div class=\"file border_bottom\" style=\"height: 57px;\">"+
										"<div class=\"text-c\" style=\"height:100%;width: 8%;float: left;padding:15px 8px;\">"+
											"<input type=\"checkbox\" name=\"del_cbx\" id=\""+e.id+"\">"+
										"</div>"+
										"<div style=\"height: 100%;width: 50%;float: left;padding: 8px;\">"+
				  						"<div style=\"height: 100%;width: 10%;float: left\">"+
				  							"<div class=\" "+e.imgClass+" ico_cnt\"style=\"float: left;\"></div>"+
				  						"</div>"+
										"<div class=\"row ver-middle\" style=\"float: left\">"+
											"<div class=\"\">"+
												"<a href=\"dowloadFile.action?id="+e.id+" \" target=\"_blank\" style=\"margin-right: 5px;\">"+e.fileName+"</a>"+
											"</div>"+
											"<div class=\"\" id=\""+e.id+"\">"+
												"<a href=\"dowloadFile.action?id="+e.id+" \" target=\"_blank\" style=\"font-size: 12px;color: #06c;\">下载</a>"+
												"<a class=\"ml_10 \" style=\"font-size: 12px;color: #06c;\">预览</a>"+
												"<a class=\"ml_10 \" style=\"font-size: 12px;color: #06c;\">更新</a>"+
												"<a class=\"ml_10 \" style=\"font-size: 12px;color: #06c;\">属性</a>"+
											"</div>"+
										"</div>"+
									"</div>"+
									"<div class=\"\"style=\"height: 100%;width: 17%;float:left;padding: 15px 8px;\">"+
										"<span class=\"muted\">"+e.humanName+"</span>"+
									"</div>"+
									"<div class=\"ver-middle\" style=\"height: 100%;width: 25%;float: left;padding: 12px 8px;\">"+
										"<span class=\"muted\">"+e.createTime+"</span>"+
									"</div>"+
								"</div>";
							$(".file_list").append(fileStr);
				 });
				 $("#uploadFileModal").modal('hide');
				 //TODO
			 },
			 error:function(data){
				 console.info(data);
			 }
		  });
	  });
  });
  function uploadfile(){
	  var name=$("#upFile").val();
	  var index=name.lastIndexOf("\\");
	  var fileName=name.substring(index+1,name.length);
	  var file=document.getElementById('upFile').files[0];
	  var fileSize="";
	  if (file.size > 1024 * 1024)
          fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
      else
          fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
	  console.info(name+fileSize+fileName);
	  $.ajaxFileUpload({
			url:"asynUpload.action",
			secureuri:false,
			fileElementId:'upFile',
			dataType:'json',
			success:function(data,status){
				console.info(data);
				var filePath=data.filePath;
				console.info(filePath);
				var file="<div class=\"row file\">"+
							"<div class=\"col-xs-6\">"+
								"<span class=\"\">"+fileName+"</span>"+
							"</div>"+
							"<div class=\"col-xs-4\">"+
								"<span class=\"muted fileSize \" id=\""+fileSize+"\"> ("+fileSize+") </span>"+
								"<button value=\""+filePath+"\" class=\"btn btn-link padding_clear filePath\">删除</button>"+
							"</div>"+
						 "</div>";
				$("#fileUploadList").append(file);
				//$("#serverFilePath").val(filePath);
			},
			error:function(data,status){
				console.info(data);
			}
		});
	  
  }
  function clickinput(){
	  return $("#upFile").click();
  }
  
  </script>
</html>
